/**
 * 用户将store中的数据转换成后端需要的数据机构格式
 *
 */
export default function useStoreToData(jsonData) {
  //配方
  let recipe = jsonData.recipe;
  //卷盘
  let reel = jsonData.reelConfig;
  let reelLabels = [];
  let reelProLabels = [];
  //包装袋
  let mbb = jsonData.packageConfig;
  let bagLabels = [];
  let bagProLabels = [];
  //盒子
  let innerBox = jsonData.innerBox;
  let boxLabels = [];
  let boxProLabels = [];
  //物料
  let desiccants = []; //干燥剂
  let humiditys = []; //湿度卡

  for (let list of reel.reelList) {
    for (let item of list.frontComponentList) {
      if (item.type == "Labels" && !item.isProLabel) {
        reelLabels.push(item);
      } else if (item.type == "ProLable") {
        reelProLabels.push(item);
      } else if (item.type == "Desiccant") {
        desiccants.push(item);
      } else if (item.type == "Humidity") {
        humiditys.push(item);
      }
    }
    for (let item of list.oppositeComponentList) {
      if (item.type == "Labels" && !item.isProLabel) {
        reelLabels.push(item);
      } else if (item.type == "ProLable") {
        reelProLabels.push(item);
      } else if (item.type == "Desiccant") {
        desiccants.push(item);
      } else if (item.type == "Humidity") {
        humiditys.push(item);
      }
    }
  }

  for (let pkg of mbb.packageList) {
    for (let item of pkg.frontComponentList) {
      if (item.type == "Labels" && !item.isProLabel) {
        bagLabels.push(item);
      } else if (item.type == "ProLable") {
        bagProLabels.push(item);
      }
    }
    for (let item of pkg.oppositeComponentList) {
      if (item.type == "Labels" && !item.isProLabel) {
        bagLabels.push(item);
      } else if (item.type == "ProLable") {
        bagProLabels.push(item);
      }
    }
  }

  for (let box of innerBox.boxList) {
    for (let item of box.leftComponentList) {
      if (item.type == "Labels" && !item.isProLabel) {
        boxLabels.push(item);
      } else if (item.type == "ProLable") {
        boxLabels.push(item);
      }
    }
    for (let item of box.rightComponentList) {
      if (item.type == "Labels" && !item.isProLabel) {
        boxLabels.push(item);
      } else if (item.type == "ProLable") {
        boxLabels.push(item);
      }
    }
    for (let item of box.downComponentList) {
      if (item.type == "Labels" && !item.isProLabel) {
        boxLabels.push(item);
      } else if (item.type == "ProLable") {
        boxLabels.push(item);
      }
    }
    for (let item of box.upComponentList) {
      if (item.type == "Labels" && !item.isProLabel) {
        boxLabels.push(item);
      } else if (item.type == "ProLable") {
        boxLabels.push(item);
      }
    }
    for (let item of box.frontComponentList) {
      if (item.type == "Labels" && !item.isProLabel) {
        boxLabels.push(item);
      } else if (item.type == "ProLable") {
        boxLabels.push(item);
      }
    }
    for (let item of box.backComponentList) {
      if (item.type == "Labels" && !item.isProLabel) {
        boxLabels.push(item);
      } else if (item.type == "ProLable") {
        boxLabels.push(item);
      }
    }
  }

  return {
    id: jsonData.id,
    jsTempStr: JSON.stringify(jsonData),
    reelLabels,
    reelProLabels,
    bagLabels,
    bagProLabels,
    boxLabels,
    boxProLabels,
    desiccants,
    humiditys,
    ...recipe,
    ...reel,
    ...mbb,
    ...innerBox,
    auditResults: false,
  };
}
